<template>
	<el-container v-loading="loading">
		<el-container>
			<el-header>
				<div class="left-panel">

				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.patient_name" placeholder="就诊人姓名" clearable></el-input>
						<el-input v-model="search.username" placeholder="用户姓名" clearable></el-input>
						<el-select v-model="search.company_id" placeholder="单位名称" style="min-width:25%;" filterable>
							<el-option v-for="item in companyList" :key="item.company_id" :label="item.company_name" :value="item.company_id">
							</el-option>
						</el-select>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="resetsearch">重置</el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable ref="table" :apiObj="apiObj" @selection-change="selectionChange" stripe remoteSort
						 remoteFilter>
					<el-table-column type="selection" width="50"></el-table-column>
					<el-table-column label="ID" prop="patient_id" width="100"></el-table-column>
					<el-table-column label="就诊人姓名" prop="patient_name" width="150"></el-table-column>
					<el-table-column label="性别" prop="sex_name" width="150"></el-table-column>
					<el-table-column label="年龄" prop="age" width="150"></el-table-column>
					<el-table-column label="出生日期" prop="birthday" width="150"></el-table-column>
					<el-table-column label="用户姓名" prop="username" width="150"></el-table-column>
					<el-table-column label="单位名称" prop="company_name" width="200"></el-table-column>
					<el-table-column label="创建时间" prop="created_at" width="170"></el-table-column>
					<el-table-column label="创建人" prop="created_by" width="170"></el-table-column>
					<el-table-column label="操作" fixed="right" align="right" width="160">
						<template #default="scope">
							<el-button-group>
								<el-button text type="primary" size="small"
										   @click="patientOrder('show',scope.row, scope.$index)">问诊记录
								</el-button>
							</el-button-group>
						</template>
					</el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>

	export default {
		name: 'user',
		components: {
		},
		data() {
			return {
				showGroupLoading: false,
				loading: false,
				apiObj: this.$API['user.user_patient'].index,
				selection: [],
				companyList: [],
				search: {
					username: null,
					patient_name: null,
					company_id: null,
				}
			}
		},
		mounted() {
			//获取单位列表
			this.getCompanyList()
		},
		methods: {
			getCompanyList() {
				this.$API['company.company'].getCompanyList.get().then((res) => {
					if (res.code == 0) {
						this.companyList = res.data;
					}
				}).catch((msg) => {
					this.$alert(msg, "提示", {type: 'error'})
				})
			},
			//问诊记录
			patientOrder(mode, row) {
				this.$router.push({
					path: '/patient/patient_order',
					query: {
						patient_id: row['patient_id'],
						patient_name: row['patient_name'],
					}
				})
			},
			//表格选择后回调事件
			selectionChange(selection) {
				this.selection = selection;
			},
			//搜索
			upsearch() {
				this.$refs.table.upData(this.search)
			},
			//重置
			resetsearch() {
				this.search = {
					username: null,
					patient_name: null,
					company_id: null,
				}
			},
			//本地更新数据
			handleSuccess() {
				this.dialog.save = false
				this.$refs.table.reload()
			},
		}
	}
</script>

<style>
</style>
